//------------------------------------------------------------------------
// <copyright file="TaggerController.cs" company="DevDir">
//   Copyleft (c) DevDir. No rights reserved.
// </copyright>
// <author>Nikita Sharov</author>
//------------------------------------------------------------------------

namespace DevDir.Mp3.Equilibrist
{
  using System.Drawing;
  using System.Windows.Forms;
  using DevDir.Mp3.Equilibrist.Forms;
  using DevDir.Mp3.Equilibrist.Controls;
  
  public class TaggerController : IModule
  {
    private TaggerControl control = new TaggerControl();
    private ToolStripSeparator separator = new ToolStripSeparator();
    private ToolStripButton refreshButton = new ToolStripButton();

    public TaggerController()
    {
      this.control.Dock = DockStyle.Fill;
      this.control.DataSource = FileExplorer.Instance.Data;

      this.refreshButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
      this.refreshButton.Image = Properties.Resources.Refresh;
      this.refreshButton.ImageTransparentColor = Color.Magenta;
      this.refreshButton.Text = "Refresh";
      this.refreshButton.Click += 
        new System.EventHandler(RefreshButtonClick);
    }
    
    public void Enter(MainForm form)
    {
      // HACK: Damn deep water.
      form.ToolStrip.Items.Add(this.separator);
      form.ToolStrip.Items.Add(this.refreshButton);
      form.Panel.Controls.Add(this.control);
    }

    public void Leave(MainForm form)
    {
      // HACK: Damn deep water.
      form.ToolStrip.Items.Remove(this.separator);
      form.ToolStrip.Items.Remove(this.refreshButton);
      form.Panel.Controls.Clear();
    }

    private void RefreshButtonClick(object sender, System.EventArgs e)
    {
      FileExplorer.Instance.Scan();
    }
  }
}
